import queue

import matplotlib.pyplot as plt
import numpy as np

data_queue = queue.Queue()
data = "1,2,3,4\n5,6,7,8\n9,10,11,12\n13,14,15,16\n"
data = data.splitlines()
print(data)

plot_data_list = [[], [], [], []]

if __name__ == "__main__":
    """
    1
    """

    # numarray = np.genfromtxt(data, dtype=int, delimiter=',')
    # print(numarray)
    # print(numarray.size)
    # if numarray.size != 20:
    #     print("hi")
    #     print(numarray == 0x43)
    #     print("received data")
    #
    #     data_queue.put(numarray)
    #
    #     numarray = data_queue.get()
    #     print(numarray)
    #
    #     for i in range(4):
    #         plot_data_list[i].append(numarray[:, i])
    #         print(plot_data_list[i])

    """
    2
    """

    # 波形参数
    frequency = 50  # Hz，波形频率
    amplitude = 1.0  # V，波形幅度
    duration = 0.02  # s，波形持续时间
    sample_rate = 1000  # Hz，采样率
    # 生成单极性方波
    t = np.linspace(0, duration, int(sample_rate * duration), endpoint=False)
    square_wave = amplitude * np.sign(np.sin(2 * np.pi * frequency * t))

    # # 将单极性方波转换为双极性方波
    bipolar_wave = square_wave - np.mean(square_wave)
    bipolar_wave = np.append(bipolar_wave, np.zeros(30))
    # # 重复三次
    bipolar_wave = np.tile(bipolar_wave, 3)
    plt.plot(bipolar_wave)
    plt.show()
